/**
 * @author		Sergey Suzdalskiy
 * @e-mail:		sergey.suzdalskiy@gmail.com
 */
package ua.kiev.gcore.ui.controls
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.filters.ColorMatrixFilter;
	import flash.filters.GlowFilter;
	import flash.text.TextField;

	public class ButtonFactory
	{
		
		
		public static var BUTTON_UP_FILTER:Array = [];
		public static var BUTTON_DOWN_FILTER:Array = [];
		public static var BUTTON_OVER_FILTER:Array = [new GlowFilter(0xffffff)];
		public static var BUTTON_DISABLE_FILTER:Array = [new ColorMatrixFilter([.33, .33, .33, 0, 0, .33, .33, .33, 0, 0, .33, .33, .33, 0, 0, 0, 0, 0, 1, 0])];
		
		public static var BUTTON_OVER_SCALE:int = 4;
		
		public static function setButtonFilters(BUTTON_UP_FILTER:Array, BUTTON_DOWN_FILTER:Array,
			BUTTON_OVER_FILTER:Array, BUTTON_DISABLE_FILTER:Array):void{
			
			ButtonFactory.BUTTON_UP_FILTER = BUTTON_UP_FILTER;
			ButtonFactory.BUTTON_DOWN_FILTER = BUTTON_DOWN_FILTER;
			ButtonFactory.BUTTON_OVER_FILTER = BUTTON_OVER_FILTER;
			ButtonFactory.BUTTON_DISABLE_FILTER = BUTTON_DISABLE_FILTER;	
		}
		
		public static function getButtonMovieClip(UID:String, movieClip:MovieClip, text:String = "", mouseClickFunction:Function = null):ButtonMovieClip{
			var backGround:MovieClip;
			var textField:TextField;
			
			if(movieClip.hasOwnProperty("bg") && movieClip["bg"] is MovieClip){
				backGround = movieClip["bg"];
			}else{
				backGround = movieClip;
			}
			
			if(movieClip.hasOwnProperty("label") && movieClip["label"] is TextField){
				textField = movieClip["label"];
			}
			
			var result:ButtonMovieClip = new ButtonMovieClip(UID, backGround, textField, text, mouseClickFunction);
			
			return result;
		}
		
		public static function getButtonSelect(UID:String, movieClip:MovieClip, text:String = "", mouseClickFunction:Function = null):ButtonSelect{
			var backGround:MovieClip;
			var textField:TextField;
			
			if(movieClip.hasOwnProperty("bg") && movieClip["bg"] is MovieClip){
				backGround = movieClip["bg"];
			}else{
				backGround = movieClip;
			}
			
			if(movieClip.hasOwnProperty("label") && movieClip["label"] is TextField){
				textField = movieClip["label"];
			}
			
			var result:ButtonSelect = new ButtonSelect(UID, backGround, textField, text, mouseClickFunction);
			
			return result;
		}
		
		public static function getButtonSprite(UID:String, movieClip:DisplayObject, text:String = "", mouseClickFunction:Function = null):ButtonSprite{
			var backGround:DisplayObject;
			var textField:TextField;
			
			if(movieClip.hasOwnProperty("bg") && movieClip["bg"] is MovieClip){
				backGround = movieClip["bg"];
			}else{
				backGround = movieClip;
			}
			
			if(movieClip.hasOwnProperty("label") && movieClip["label"] is TextField){
				textField = movieClip["label"];
			}
			
			var result:ButtonSprite = new ButtonSprite(UID, backGround, textField, text, mouseClickFunction);
			
			return result;
		}
		
		public static function getCheckButton(UID:String, movieClip:MovieClip, text:String = "", mouseClickFunction:Function = null):CheckButton{
			var backGround:MovieClip;
			var textField:TextField;
			
			if(movieClip.hasOwnProperty("bg") && movieClip["bg"] is MovieClip){
				backGround = movieClip["bg"];
			}else{
				backGround = movieClip;
			}
			
			if(movieClip.hasOwnProperty("label") && movieClip["label"] is TextField){
				textField = movieClip["label"];
			}
			
			var result:CheckButton = new CheckButton(UID, backGround, textField, text, mouseClickFunction);
			
			return result;
		}
			
	}
}